const { parseString } = require('xml2js')

module.exports = {
    //获取用户信息
    getUserData(req) {
        let str = ''
        return new Promise((resolve, reject) => {
            req
                .on('data', data => {
                    // console.log(data);
                    str += data
                })
                .on('end', () => {
                    resolve(str)
                })
        })
    },
    //把xml格式转换成对象形式
    formatData(xmlData) {
        return new Promise((resolve, reject) => {
            parseString(xmlData, (err, data) => {
                if (!err) {
                    resolve(data.xml)
                }
            })
        })
    },
    //转换成对象格式
    formatDataJs(data) {
        let obj = {}
        for (const key in data) {
            obj[key] = data[key][0]
        }
        return obj
    }
}